import { useForm } from "../../framework/common/context/metadata-context";
import get from "lodash/get";
import { Tooltip } from "antd";
import "./index.css";
import { useUpdate } from "ahooks";
import { useSubscribe } from "../../framework/common/eventBus";
export default function RemarkTip({ codePath }) {
  const { data: tplData,mode } = useForm().root;
  let isPrint=(mode==="Print")
  const updater = useUpdate();
  useSubscribe("refreshRemarkTip." + codePath,()=>{
    updater();//监听更新
  })
  if(isPrint) return null;//打印模式不显示提示


  let options = get(tplData, codePath);
  //是否有需要显示的RemarkTip
  if (Array.isArray(options) && options.length > 0) {
    //options拿到的是这样的结构
    //[[0, "武汉", "说明1", "wuhan"], [0, "北京", "说明2", "beijing"]]
    //这里老系统多选有Bug 取的是索引1,2
    //应该是取1,3
    //新版版全部取1,3
    //根据老数据分析，数组元素第一位为0 '0'或者1 '1'的才需要显示remarkTip
    if (options[0]?.[0] !== 0&&options[0]?.[0] !== '0'&&options[0]?.[0] != 1) {
      return null;
    }
    //Tip内容组件
    function TipContent() {
      return (
        <span className="tipWrapText" style={{ maxHeight: "349px", overflow: "auto" }}>
          <ul className="remark-tip-all">
            {options.map((option = [], index) => (
              <li key={index}>
                <span>
                  {option[1]} {option[3]&&":"} {option[3]}
                </span>
              </li>
            ))}
          </ul>
        </span>
      );
    }
    return (
      <Tooltip
          getPopupContainer={() => document.querySelector(".main-content")}
          overlayClassName="bottomTip"
          color="white"
          placement="bottom"
          title={<TipContent></TipContent>}
          >
        <i className="ml-1 font-normal hover:text-primary text-13px text-gray-b1 remark-tip icon-bangzhu iconfont"></i>
      </Tooltip>
    );
  }

  return null;
}
